home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 83
/
(Vol 83) My Disc.iso
/
Games
/
hello_kitty.swf
/
scripts
/
frame_1
/
DoAction.as
Wrap
Text File
|
2008-08-07
|
7KB
|
239 lines
function buildMap(map)
{
_root.attachMovie("empty","tiles",++d);
game.clip = _root.tiles;
game.clip._x = gameInitial_x;
game.clip._y = gameInitial_y;
var mapWidth = map[0].length;
var mapHeight = map.length;
var i = 0;
while(i < mapHeight)
{
var j = 0;
while(j < mapWidth)
{
var name = "t_" + i + "_" + j;
game[name] = new game["Tile" + map[i][j]]();
game.clip.attachMovie("tile",name,i * 100 + j * 2);
game.clip[name]._x = j * game.tileW;
game.clip[name]._y = i * game.tileH;
game.clip[name].gotoAndStop(game[name].frame);
j++;
}
i++;
}
game.items = myItems;
var i = 0;
while(i < game.items.length)
{
var name = "item" + game.items[i][2] + "_" + game.items[i][1];
game[name] = new game["Item" + game.items[i][0]]();
game[name].position = i;
game.clip.attachMovie("item",name,10001 + i);
game[name].clip = game.clip[name];
game[name].clip._x = game.items[i][1] * game.tileW + game.tileW / 2;
game[name].clip._y = game.items[i][2] * game.tileH + game.tileH / 2;
game[name].clip.gotoAndStop(game.items[i][0]);
i++;
}
_root.points = game.points;
var enemies = myEnemies;
game.currentEnemies = enemies.length;
var i = 0;
while(i < game.currentEnemies)
{
var name = "enemy" + i;
game[name] = new game["Enemyp" + enemies[i][0]]();
game.clip.attachMovie("enemy1",name,10012 + i);
game[name].clip = game.clip[name];
game[name].xtile = enemies[i][1];
game[name].ytile = enemies[i][2];
game[name].width = game.clip[name]._width / 2;
game[name].height = game.clip[name]._height / 2;
game[name].x = game[name].xtile * game.tileW + game.tileW / 2;
game[name].y = game[name].ytile * game.tileH + game.tileH / 2;
game[name].clip._x = game[name].x;
game[name].clip._y = game[name].y;
i++;
}
game.clip.attachMovie("char","char",1000);
char.clip = game.clip.char;
char.x = char.xtile * game.tileW + game.tileW / 2;
char.y = char.ytile * game.tileH + game.tileH / 2;
char.width = char.clip._width / 2;
char.height = char.clip._height / 2;
char.clip._x = char.x;
char.clip._y = char.y;
}
function enemyBrain()
{
var i = 0;
while(i < 5)
{
var name = "enemy" + i;
var ob = game[name];
getMyCorners(ob.x + ob.speed * ob.xMove,ob.y + ob.speed * ob.yMove,ob);
if(ob.downleft and ob.upleft and ob.downright and ob.upleft)
{
moveChar(ob,ob.xMove,ob.yMove);
}
else
{
ob.xMove = - ob.xMove;
ob.yMove = - ob.yMove;
}
if(!_root.infiniteLife)
{
var xdist = ob.x - char.x;
var ydist = ob.y - char.y;
if(math.sqrt(xdist * xdist + ydist * ydist) < ob.width + char.width)
{
_root.lifes -= 1;
mylifes.gotoAndStop(_root.lifes);
if(lifes == 0)
{
removeMovieClip(_root.tiles);
_root.gotoAndStop(35);
}
if(!_root.hurt)
{
char.clip.gotoAndPlay("hurt");
return undefined;
}
}
}
i++;
}
}
function starting_point()
{
char.x = startingXtile * game.tileW + game.tileW / 2;
char.y = startingYtile * game.tileH + game.tileH / 2;
char.clip._x = char.x;
char.clip._y = char.y;
}
function detectKeys()
{
var ob = _root.char;
var keypressed = false;
if(key.isDown(39))
{
keyPressed = _root.moveChar(ob,1,0);
}
else if(key.isDown(37))
{
keyPressed = _root.moveChar(ob,-1,0);
}
else if(key.isDown(38))
{
keyPressed = _root.moveChar(ob,0,-1);
}
else if(key.isDown(40))
{
keyPressed = _root.moveChar(ob,0,1);
}
if(!KeyPressed)
{
ob.clip.mychar.gotoAndStop(1);
}
else
{
ob.clip.mychar.play();
}
enemyBrain();
}
function moveChar(ob, dirx, diry)
{
getMyCorners(ob.x,ob.y + ob.speed * diry,ob);
if(diry == -1)
{
if(ob.upleft and ob.upright)
{
ob.y += ob.speed * diry;
}
else
{
ob.y = ob.ytile * game.tileH + ob.height;
}
}
if(diry == 1)
{
if(ob.downleft and ob.downright)
{
ob.y += ob.speed * diry;
}
else
{
ob.y = (ob.ytile + 1) * game.tileH - ob.height;
}
}
getMyCorners(ob.x + ob.speed * dirx,ob.y,ob);
if(dirx == -1)
{
if(ob.downleft and ob.upleft)
{
ob.x += ob.speed * dirx;
}
else
{
ob.x = ob.xtile * game.tileW + ob.width;
}
}
if(dirx == 1)
{
if(ob.upright and ob.downright)
{
ob.x += ob.speed * dirx;
}
else
{
ob.x = (ob.xtile + 1) * game.tileW - ob.width;
}
}
ob.clip._x = ob.x;
ob.clip._y = ob.y;
ob.clip.gotoAndStop(dirx + diry * 2 + 3);
ob.xtile = Math.floor(ob.clip._x / game.tileW);
ob.ytile = Math.floor(ob.clip._y / game.tileH);
var itemname = game["item" + ob.ytile + "_" + ob.xtile];
if(itemname and ob == _root.char)
{
game.points = true;
removeMovieClip(itemname.clip);
game.items[itemname.position] = 0;
delete game["item" + ob.ytile + "_" + ob.xtile];
if(game.points = true)
{
opendoorname = "t_" + unlockY + "_" + unlockX;
game.clip[opendoorname].gotoAndStop(4);
game.Tile2.prototype.walkable = true;
}
}
if(_root.char.ytile == unlockY && _root.char.xtile == unlockX && _root.unlock)
{
removeMovieClip(_root.tiles);
_root.unlock = false;
_root.nextFrame();
}
return true;
}
function getMyCorners(x, y, ob)
{
ob.downY = Math.floor((y + ob.height - 1) / game.tileH);
ob.upY = Math.floor((y - ob.height) / game.tileH);
ob.leftX = Math.floor((x - ob.width) / game.tileW);
ob.rightX = Math.floor((x + ob.width - 1) / game.tileW);
ob.upleft = game["t_" + ob.upY + "_" + ob.leftX].walkable;
ob.downleft = game["t_" + ob.downY + "_" + ob.leftX].walkable;
ob.upright = game["t_" + ob.upY + "_" + ob.rightX].walkable;
ob.downright = game["t_" + ob.downY + "_" + ob.rightX].walkable;
}
gameInitial_x = 75;
gameInitial_y = 106;
hurt = false;
unlock = false;
lifes = 4;
infiniteLife = false;
stop();
var tempLv = 0;